﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WXYW.BLL;
using WXYW.Model;

namespace WXYW
{
    public partial class ZBTJ0T5TAT : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                for (int i = 2010; i <= DateTime.Now.Year; i++)
                {
                    yearDropDownList.Items.Add(new ListItem(i.ToString(), i.ToString()));
                }
                yearDropDownList.SelectedIndex = yearDropDownList.Items.Count - 1;

                for (int i = 2010; i <= DateTime.Now.Year; i++)
                {
                    tyearDropDownList.Items.Add(new ListItem(i.ToString(), i.ToString()));
                }
                tyearDropDownList.SelectedIndex = tyearDropDownList.Items.Count - 1;

                for (int i = 1; i <= 12; i++)
                {
                    monthDropDownList.Items.Add(new ListItem(i.ToString(), i.ToString()));
                }
                monthDropDownList.SelectedIndex = DateTime.Now.Month == 1 ? 0 : DateTime.Now.Month-2;

                for (int i = 1; i <= 12; i++)
                {
                    tmonthDropDownList.Items.Add(new ListItem(i.ToString(), i.ToString()));
                }
                tmonthDropDownList.SelectedIndex = DateTime.Now.Month - 1;


                BindData();
            }
        }

        private void BindData()
        {
            ZBTJService service = new ZBTJService();
            List<ZBTJModel> models = service.Get0TXTAT(Convert.ToInt32(yearDropDownList.SelectedValue), Convert.ToInt32(monthDropDownList.SelectedValue),
                Convert.ToInt32(tyearDropDownList.SelectedValue), Convert.ToInt32(tmonthDropDownList.SelectedValue), 5);
            ZBGridView.DataSource = models;
            ZBGridView.DataBind();

            List<ZBTJModel> qmodels = service.GetQ0T5TAT(Convert.ToInt32(yearDropDownList.SelectedValue)-1, Convert.ToInt32(tyearDropDownList.SelectedValue));
            JDZBGridView.DataSource = qmodels;
            JDZBGridView.DataBind();

            string xstrings = string.Empty;
            string ystrings = string.Empty;
            foreach (ZBTJModel model in models)
            {
                xstrings += "|" +model.Month;
                ystrings += model.ZB.ToString() + ",";
            }
            if (ystrings.Length > 1)
            {
                ystrings = ystrings.Remove(ystrings.Length - 1);
            }
            ZBImage.ImageUrl = string.Format("http://chart.googleapis.com/chart?cht=lc&chxt=x,y&chs=800x300&chxl=0:{0}|&chs=300x200&chd=t:{1}&chf=bg,s,65432100", HttpUtility.UrlEncode(xstrings), ystrings);

            string xstrings1 = string.Empty;
            string ystrings1 = string.Empty;
            foreach (ZBTJModel model in qmodels)
            {
                xstrings1 += "|" + model.Month;
                ystrings1 += model.ZB.ToString() + ",";
            }
            if (ystrings1.Length > 1)
            {
                ystrings1 = ystrings1.Remove(ystrings1.Length - 1);
            }

            JDZBImage.ImageUrl = string.Format("http://chart.googleapis.com/chart?cht=lc&chxt=x,y&chs=800x300&chxl=0:{0}|&chs=300x200&chd=t:{1}&chf=bg,s,65432100", HttpUtility.UrlEncode(xstrings1), ystrings1);
            YSTJGridView.DataSource = service.GetYSTJ(Convert.ToInt32(yearDropDownList.SelectedValue), Convert.ToInt32(monthDropDownList.SelectedValue),
                Convert.ToInt32(tyearDropDownList.SelectedValue), Convert.ToInt32(tmonthDropDownList.SelectedValue));
            YSTJGridView.DataBind();
        }

        protected void OKButton_Click(object sender, EventArgs e)
        {
            BindData();
        }
    }
}
